package models

import (
	"mini-app/internal/define"

	"gorm.io/gorm"
)

// GoodsSetting 商品设置
type GoodsSetting struct {
	GoodsID     string `json:"goods_id" gorm:"column:goods_id;primaryKey;type:int;size:64;comment:主键"`
	RobotID     string `json:"robot_id" gorm:"column:robot_id;type:string;size:30;index:idx_robotID;primaryKey;comment:设备id"`
	GoodsClass  string `json:"goods_class" gorm:"column:goods_class;type:string;size:100;index:idx_goods_class;comment:展示分类"`
	PickupType  string `json:"pickup_type" gorm:"column:pickup_type;type:string;size:10;default:1;comment:取货方式，1-自提,2-邮寄"`
	Tag         string `json:"tag" gorm:"column:tag;type:string;size:100;comment:商品标签，多个以逗号分隔"`
	CornerLabel string `json:"corner_label" gorm:"column:corner_label;type:string;size:100;comment:商品脚标，多个以逗号分隔"`
	Visible     int    `json:"visible" gorm:"column:visible;type:int;default:2;size:8;comment:是否展示，1-展示 2-不展示"`
	CreatedAt   int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64"`
	UpdatedAt   int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64"`
}

func (GoodsSetting) TableName() string {
	return "goods_setting"
}

// AfterFind 查询后 Hook - 在 Find 操作后执行
func (g *GoodsSetting) AfterFind(tx *gorm.DB) (err error) {
	if g.Visible == 0 {
		g.Visible = define.State_No // 这个因为老版本配置数据库tag笔误，default:2写成defaut:2，导致有0默认值
	}

	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &GoodsSetting{})
}
